<template>
  <div>
    <el-dialog
      title="会员编辑"
      :visible.sync="info.isshow"
      @closed="closed"
    >
    {{user}}
      <el-form :model="user">
        <el-form-item label="手机号" label-width="120px">
          <el-input v-model="user.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="昵称" label-width="120px">
          <el-input v-model="user.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" label-width="120px">
          <el-input v-model="user.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" label-width="120px">
        <el-switch
          v-model="user.status"
          :active-value="1"
          :inactive-value="2"
        ></el-switch>
      </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="update">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { memberedit, memberinfo } from '../../../http/api';
import { successAlert } from "../../../utils/alert";
export default {
  props: ["info"],
  data() {
    return {
      user: {
        nickname: "",
        phone:"",
        password: "",
        status: 1,
      },
      
    };
  },
  computed: {
    ...mapGetters({
      list:"vip/list"
    }),
  },
  methods: {
    ...mapActions({
      reqList:"vip/reqList"
    }),
    //取消
    cancel(){
      this.info.isshow=false
    },
    //清空
    empty(){
      this.user={
        nickname: "",
        phone:"",
        password: "",
        status: 1,
      }
    },

    //获取一个数据
    getOne(uid){
      memberinfo({uid}).then(res=>{
        if(res.data.code==200){
          this.user=res.data.list;
          // //补id字段,发送修改时需要使用
          this.user.uid=uid;
          this.user.password="";
        }
      })
    },
    update(){
      memberedit(this.user).then(res=>{
        if(res.data.code=200){
          successAlert(res.data.msg);
          this.info.isshow=false;
          this.empty();
          //通知父组件刷新表格
          this.reqList();
        }
      })
    },
    //如果是编辑窗口取消，清空数据，添加窗口的取消，不需要清空
    closed(){
      if(!this.info.isAdd){
        this.empty()
      }
    }
  },
};
</script>

<style>
</style>